import 'package:flutter/material.dart';
import 'package:flutter_base/pages/test_detail/widgets/test_badge_block.dart';
import 'package:flutter_base/pages/test_detail/widgets/test_growth_path_block.dart';
import 'package:flutter_base/pages/test_detail/widgets/test_keyword_tag_block.dart';
import 'package:flutter_base/pages/test_detail/widgets/test_matching_result_block.dart';
import 'package:flutter_base/pages/test_detail/widgets/test_multi_dimensional_analysis_card.dart';
import 'package:flutter_base/pages/test_detail/widgets/test_quote_image_block.dart';
import 'package:flutter_base/pages/test_detail/widgets/test_radar_chart_block.dart';
import 'package:flutter_base/pages/test_detail/widgets/test_recommendation_box.dart';
import 'package:flutter_base/pages/test_detail/widgets/test_text_progress_block.dart';
import 'package:flutter_base/pages/test_detail/widgets/test_visual_meter_block.dart';
import 'package:flutter_base/pages/test_result/model/model_test_result.dart';
import 'package:flutter_base/utils/log/utils_log.dart';

/// 测试结果组件工具类
class TestResultComponentUtil {
  /// 根据组件类型和数据生成对应的组件
  static Widget buildComponentByType(
      ModelTestResultResultComponents components) {
    switch (components.type) {
      case 'MatchingResultBlock':
        return TestMatchingResultBlock(componentsData:components.data);

      case 'KeywordTagBlock':
        return const TestKeywordTagBlock();

      case 'MultiDimensionalBlock':
        return TestMultiDimensionalAnalysisCard(testDetail: null);

      case 'RadarChartBlock':
        return TestRadarChartBlock(testDetail: null);

      case 'QuoteImageBlock':
        // final quoteData = data as Map<String, dynamic>?;
        return TestQuoteImageBlock(
          data: components.data,
          // imageUrl: quoteData?['imageUrl'] as String?,
          // quote: quoteData?['quote'] as String?,
        );

      case 'RecommendationBox':
        return TestRecommendationBox(testDetail: null);

      case 'BadgeBlock':
        // final badgeData = data as Map<String, dynamic>?;
        // if (badgeData != null && badgeData['badges'] != null) {
        return TestBadgeBlock(
          data: components.data,
        );
      // }
      // return TestBadgeBlock(testDetail: testDetail);

      case 'GrowthPathBlock':
        return TestGrowthPathBlock(
          currentStage: 4,
          testDetail: null,
          items: const [
            'Self-awareness',
            'Skill Development',
            'Practical application',
            'Continuous optimization',
            'Influencing Others'
          ],
        );

      case 'TextProgressBlock':
        return TextProgressBlock(
          data: components.data,
        );

      case 'VisualMeterBlock':
        return TestVisualMeterBlock(
          data: components.data,
        );

      default:
        return const SizedBox(); // 默认返回空组件
    }
  }
}
